var express = require('express');
var router = express.Router();
const orderService = require('../service/orderService');

//新增
router.post('/', async function (req, res) {
  console.log(req.body);
  let { address, receiver, date, telephone, status } = req.body;
  //对象集合需要用json格式传过来采用,需要转换才能存进去正确的对象集合
  // seats = JSON.parse(seats);
  let data = await orderService.create({ address, receiver, date, telephone, status });
  res.send(data);
});

//查询
router.get('/', async function (req, res) {
  let { key, value, current, pageSize } = req.query;
  let searchParams = {};
  searchParams[key] = value;
  let data = await orderService.find({ current: current || 1, pageSize: pageSize || 10 }, searchParams);
  res.send(data);
});
//按照id删除
router.delete('/:id', async function (req, res) {
  let { id } = req.params;
  let data = await orderService.delete(id);
  res.send(data);
});

module.exports = router;
 